import 'package:detect/entity/entity.dart';
import 'package:detect/utils/connect_state_util.dart';
import 'package:flutter/material.dart';

class NetworkStateNotifier extends ChangeNotifier {
  NetworkStateEntity state;

  NetworkStateNotifier._(this.state) {
    ConnectStateUtil.listen("ListenNetwork", (result) {
      NetworkStateEntity.get.then((value) {
        state = value;
        notifyListeners();
      });
    });
  }

  static Future<NetworkStateNotifier> init() => NetworkStateEntity.get.asStream().map((state) => NetworkStateNotifier._(state)).single;
}
